package com.csdj.controller.Be;

import com.csdj.common.enums.AppHttpCodeEnum;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.BeComment;
import com.csdj.service.BeCommentService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/beComment")
public class BeCommentController {

    @Autowired
    private BeCommentService beCommentService;

    /**
     * 根据工单号 查询附加信息
     * @param orderNo 工单号
     */
    @GetMapping()
    public ResponseResult getByNo(String orderNo){
        List<BeComment> list = beCommentService.getByNo(orderNo);
        return list.isEmpty()?ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"服务器繁忙"):ResponseResult.okResult(list);
    }

    /**
     * 根据id删除
     * @param id 需要删除的附加信息的id
     */
    @DeleteMapping()
    public ResponseResult delById(Integer id){
        return beCommentService.removeById(id)?ResponseResult.okResult("删除成功!"):ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"删除失败");
    }

    /**
     * 根据id修改
     * @param beComment 修改后的附加信息
     */
    @PutMapping
    public ResponseResult upById(@RequestBody BeComment beComment){
        return beCommentService.updateById(beComment)?ResponseResult.okResult("修改成功!"):ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"修改失败");
    }

    /**
     * 添加附加信息
     * @param beComment 新增的附加信息
     */
    @PostMapping()
    public ResponseResult add(@RequestBody BeComment beComment){
        beComment.setDatee(new Date());
        return beCommentService.save(beComment)?ResponseResult.okResult("添加成功!"):ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"添加失败");
    }
}
